package com.xingzhe.pengji.security.dao.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.xingzhe.pengji.framework.dao.BaseIBatisDaoImpl;
import com.xingzhe.pengji.security.dao.GroupIbatisDao;
import com.xingzhe.pengji.security.domain.Group;
import com.xingzhe.pengji.security.mapper.GroupMapper;

/**
 * @Title ： 三江学院 毕业设计
 * @Description ：
 * @author ：LuFengLiang
 * @Company: IT行者工作室
 * @Copyright: Copyright (c) 2012-2-24
 * @version ： 1.0
 * @param <T>
 */
@Repository
public class GroupIbatisDaoImpl<T extends Group> extends BaseIBatisDaoImpl<T> implements GroupIbatisDao<T>
{
    @Autowired
    private GroupMapper<T> groupMapper;

    private Logger logger = LoggerFactory.getLogger(GroupIbatisDaoImpl.class);

    @Override
    public boolean addGroup(T entity) throws DataAccessException
    {
        try
        {
            groupMapper.saveGroup(entity);
        }
        catch (Exception e)
        {
            logger.error(e.toString());
            return false;
        }
        return true;
    }

    @Override
    public boolean updateGroup(T entity) throws DataAccessException
    {
        try
        {
            groupMapper.updateGroup(entity);
        }
        catch (Exception e)
        {
            logger.error(e.toString());
            return false;
        }
        return true;
    }

    @Override
    public T getGroupById(T entity) throws DataAccessException
    {
        try
        {
            return groupMapper.getGroupById(entity.getId());
        }
        catch (Exception e)
        {
            return null;
        }
    }

    @Override
    public T getGroupByName(T entity) throws DataAccessException
    {
        try
        {
            return groupMapper.getGroupByName(entity.getName());
        }
        catch (Exception e)
        {
            return null;
        }
    }

    @Override
    public List<T> getPageList(Map<String, Object> map)
    {
        return groupMapper.queryForPaginatedList(map);
    }

    @Override
    public int getItemCount(Map<String, Object> map) throws DataAccessException
    {
        return groupMapper.getItemCount(map);
    }
}
